| Conditions | 4 |
| Total Lines | 20 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | // jshint esversion: 8 |
||
| 24 | startLine (integer) - line to start reading from |
||
| 25 | */ |
||
| 26 | function fileReadLines(filePath, lines = 2, startLine = 0) { |
||
| 27 | var lineCounter = startLine, |
||
| 28 | endLine = startLine + lines, |
||
| 29 | linesRead = [], |
||
| 30 | lineReader = require('readline').createInterface({ |
||
| 31 | input: require('fs').createReadStream(filePath), |
||
| 32 | }); |
||
| 33 | |||
| 34 | lineReader.on('line', function(line) { |
||
| 35 | lineCounter++; |
||
| 36 | linesRead.push(line); |
||
| 37 | if (lineCounter == lines) { |
||
| 38 | lineReader.close(); |
||
| 39 | } |
||
| 40 | }); |
||
| 41 | lineReader.on('close', function() { |
||
| 42 | return linesRead; |
||
| 43 | }); |
||
| 44 | } |
||
| 50 |
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: